package edu.uts.reekie.designer.implementation.figures;


import org.eclipse.draw2d.*;
import org.eclipse.draw2d.geometry.*;
import org.eclipse.gef.handles.HandleBounds;
import edu.uts.reekie.designer.figures.*;
/*
 * 
 * 
 */
public abstract class ViewComponentFigure 
		extends Figure 
		implements HandleBounds, NameableFigure, AnchorFigure, MultipleFigure {
	
	protected final Dimension DEFAULT_SIZE = new Dimension(100,100);

	
	static {
	}
	
	protected Label nameLabel;
	
	public ViewComponentFigure() {
		nameLabel = new Label();
		
		
	}


	/**
	 * @see org.eclipse.gef.handles.HandleBounds#getHandleBounds()
	 */
	public Rectangle getHandleBounds() {
		return getBounds();
	}
	
	/* (non-Javadoc)
	 * @see edu.uts.reekie.designer.conceptual.figures.AnchorBounds#getAnchorBounds()
	 */
	public IFigure getAnchorFigure() {
		return this;
	}
	
	public Dimension getPreferredSize(int w, int h) {
		Dimension prefSize = super.getPreferredSize(w, h);
		
		prefSize.union(DEFAULT_SIZE);
		return prefSize;
	}
	
	
	/**
	 * @see org.eclipse.draw2d.Figure#paintFigure(Graphics)
	 */
	protected void paintFigure(Graphics graphics) {
		
		Rectangle rect = getBounds().getCopy();
		rect.crop(new Insets(2,0,2,0));
		graphics.fillRectangle(rect);
		
	}

	/**
	 * Returns the text inside the TextFlow.
	 * 
	 * @return the text flow inside the text.
	 */
	public String getName() {
		return nameLabel.getText();
	}

	/**
	 * Sets the text of the TextFlow to the given value.
	 * 
	 * @param newText the new text value.
	 */
	public void setName(String newText) {
		nameLabel.setText(newText);
	}
	

	public String toString() {
		return "ViewComponentFigure"; //$NON-NLS-1$
	}

	public void validate() {
		if(isValid()) return;
		super.validate();
	}
	
	protected boolean isMultiple = false;
	
	public boolean isMultiple() {
		return isMultiple;
	}
	
	public void setMultiple(boolean isMul){
		if (this.isMultiple==isMul){
			return;
		}
		this.isMultiple = isMul;
		repaint();
	}
}
